﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;

namespace Algorithms
{
    public class AlgorithmFactory
    {
        public IAlgorithm GetAlgorithm(AlgorithmInfo algoInfo)
        {
            ApplicationInfo appInfo = ApplicationInfo.GetInstance();
            string plugin_FileLocation = appInfo.CurrentPath + "\\Plugins\\" + algoInfo.TargetAssembly;

            Assembly plugin_Assembly = Assembly.LoadFile(plugin_FileLocation);
            Type algo_Type = plugin_Assembly.GetType(algoInfo.TargetNamespace + "." + algoInfo.TargetAlgorithm);
            
            Type[] args = Type.EmptyTypes;
            ConstructorInfo ctro = algo_Type.GetConstructor(args);

            IAlgorithm algoSelected = ctro.Invoke(new object[] { }) as IAlgorithm;

            return algoSelected;
        }
    }
}
